package com.ma.chapter5.note;

import lombok.extern.slf4j.Slf4j;

/**
 * @ClassName Singleton
 * @Author: mayongqiang
 * @DATE 2022/3/18 21:28
 * @Description: 懒惰式单例模式  double-checked locking 解决
 */
@Slf4j(topic = "m.Singleton")
public final class Singleton {
    private static volatile Singleton INSTANCE = null;

    private Singleton() {
    }

    public static Singleton getInstance() {
        if (INSTANCE == null) {
            synchronized (Singleton.class) {
                if (INSTANCE == null) {
                    INSTANCE = new Singleton();
                }
            }
        }
        return INSTANCE;
    }

}
